package com.freetek.mvptest.View;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.Button;
import android.widget.TextView;

import com.freetek.mvptest.Presenter.IPresenter;
import com.freetek.mvptest.Presenter.Presenter;
import com.freetek.mvptest.R;

import org.w3c.dom.Text;

/**
 * Created by Chenkai on 2017/7/26.
 */

public class MainActivity extends Activity implements IView{
    private IPresenter presenter;
    private Button button;
    private TextView text;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text = (TextView)findViewById(R.id.tv_hello);
        button = (Button)findViewById(R.id.button);
        presenter=new Presenter(this); //2 Presenter初始化
        presenter.onCreate();   //3 将生命周期回调传给Presenter
        button.setOnClickListener(new android.view.View.OnClickListener() {
            @Override
            public void onClick(android.view.View v) {
                presenter.performOnClick();
            }
        });
    }
    @Override
    public void setData(final String data) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                text.setText(data);
            }
        });
    }

}
